package com.example.sqlitedemo;

import android.os.Bundle;
import android.app.ListActivity;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.Menu;

public class MainActivity extends ListActivity {

	private DBAdapter mDB;
	private Cursor mCursor;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        mDB= new DBAdapter(this);
        mDB.Open();
        mDB.createUser("Khang");
        getData();
    }
    private void getData()
    {
    	mCursor= mDB.getAllUsers();
    	startManagingCursor(mCursor);
    	String[] from=new String[] {DBAdapter.KEY_NAME};
    	int[] to=new int[] {R.id.text1};
    	SimpleCursorAdapter users= new SimpleCursorAdapter(this, R.layout.users_row, mCursor, from, to);
    	setListAdapter(users);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
